let oldArrayProto = Array.prototype // 数组原有proto

let newArrayProto = Object.create(oldArrayProto)  // 切片编程..

let methods = [  //数组的变异方法
    'push',
    'pop',
    'unshift',
    'shift',
    'splice',
    'reverse',
    'sort',
]

methods.forEach(method => {
    newArrayProto[method] = function (...args) {
        // console.log('方法重写了', this.__ob__) // this === data

        let newArrItem

        switch (method) {
            case 'push':
            case 'unshift': newArrItem = args
                break;
            case 'splice': newArrItem = args.slice(2) // slice 新加的数据 进行observer
                break;
            default:
                break;
        }

        this.__ob__.observerArray(newArrItem)
        this.__ob__.dep.notify()
        console.log('更新了', this.__ob__)

        return oldArrayProto[method].call(this, ...args)
    }
})



export default newArrayProto